package nju.software.tagmanager.common.utils;

import com.aspose.pdf.Document;
import com.aspose.pdf.HtmlSaveOptions;
import com.aspose.pdf.LettersPositioningMethods;

import java.io.ByteArrayOutputStream;

/**
 * @author: raychou
 * @date: 2023-12-07 9:21
 * @description:
 */
public class PdfToHtmlUtil {
    public static String getHtml(String path) {
        ByteArrayOutputStream html = new ByteArrayOutputStream();

        Document pdfDocument = new Document(path);
        HtmlSaveOptions htmlSaveOptions = new HtmlSaveOptions();
        htmlSaveOptions.setRasterImagesSavingMode(HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground);
        htmlSaveOptions.setFontSavingMode(HtmlSaveOptions.FontSavingModes.SaveInAllFormats);
        htmlSaveOptions.setPartsEmbeddingMode(HtmlSaveOptions.PartsEmbeddingModes.EmbedAllIntoHtml);
        htmlSaveOptions.setLettersPositioningMethod(LettersPositioningMethods.UseEmUnitsAndCompensationOfRoundingErrorsInCss);


        htmlSaveOptions.setSplitIntoPages(false);

        pdfDocument.save(html, htmlSaveOptions);
        return html.toString();
    }


}
